//Source file: D:\\test\\com\\ce\\pms\\charge\\model\\AccountDomain.java

package com.ce.pms.charge.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.*;

import com.ce.pms.common.model.SysInfo;
import com.ce.pms.customer.model.ProRightDO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.model.HouseDomain;
import com.sitechasia.webx.core.model.IDomainObject;

/**
 * 实体名称:账户 关联数据表:FEE_ACCOUNT
 * author: Adama Yue
 */
@Entity
@Table(name = "FEE_ACCOUNT")
public class AccountDomain implements IDomainObject{

	/**
	 * 账户ID
	 */
	@Id
	@GeneratedValue
	@Column(name = "ACCOUNT_ID")
	private Long accountId;

	/**
	 * 房屋
	 */
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "HOUSE_ID")
	private HouseDomain house;

	/**
	 * 产权
	 */
	@OneToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "PRO_RIGHT_ID",nullable = false)
	private ProRightDO proRight;

	/**
	 * 是否有效 1有效;0有效
	 */
	@Column(name = "IS_ACTIVE", nullable = false, length = 1)
	private String isActive;

	/**
	 * 子账户集 检索策略:lazy=false 级联配置:cascade=all-delete-orphan
	 */
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "account")
    @org.hibernate.annotations.Cascade(value = {
            org.hibernate.annotations.CascadeType.DELETE_ORPHAN/*,
            org.hibernate.annotations.CascadeType.SAVE_UPDATE*/ })
    private Set<AbstractSubAccount> subAccounts=new HashSet<AbstractSubAccount>();

	@Embedded
	protected SysInfo sysInfo;
	/**
	 * @roseuid 48757D100119
	 */
	public AccountDomain() {}
	/**
	 * @param house 房屋
	 * @param proRight 产权
	 * @param isActive 有效状态
	 */
	public AccountDomain(HouseDomain house, ProRightDO proRight, String isActive,SysInfo sysInfo) {
		super();
		this.house = house;
		this.proRight = proRight;
		this.isActive = isActive;
		this.sysInfo = sysInfo;
	}
	/*********************************************
	 * Accessors and modifiers
	 *********************************************/
	public Long getAccountId() {
		return accountId;
	}
	public void setAccountId(Long accountId) {
		this.accountId = accountId;
	}
	public HouseDomain getHouse() {
		return house;
	}
	public void setHouse(HouseDomain house) {
		this.house = house;
	}
	public String getIsActive() {
		return isActive;
	}
	public void setIsActive(String isActive) {
		this.isActive = isActive;
	}
	public ProRightDO getProRight() {
		return proRight;
	}
	public void setProRight(ProRightDO proRight) {
		this.proRight = proRight;
	}
	public Set<AbstractSubAccount> getSubAccounts() {
		return subAccounts;
	}
	public void setSubAccounts(Set<AbstractSubAccount> subAccounts) {
		this.subAccounts = subAccounts;
	}
	public SysInfo getSysInfo() {
		return sysInfo;
	}
	public void setSysInfo(SysInfo sysInfo) {
		this.sysInfo = sysInfo;
	}

    public void checkRequiredField(){
        if (this.proRight == null
                || this.proRight.getProRightId() == null
                || this.isActive == null
                || this.sysInfo == null
                || this.sysInfo.getCreator() == null
                || this.sysInfo.getSysDate() == null) {
            throw new BusinessException("common:mustFill_null_exception",
                    BusinessException.WARNING);
        }
    }

}
